import java.util.Scanner

class OperationInterface private constructor(){
    companion object{
        val instance:OperationInterface by lazy {
            OperationInterface()
        }
    }

    //显示菜单
    fun showMenu(){
        println("----------------------")
        println("1. 添加好友")
        println("2. 删除好友")
        println("3. 显示列表")
        println("4. 退出")
        println("----------------------")
    }

    //选择操作
    fun choose(callback:(OperationType)->Unit){
        val scanner = Scanner(System.`in`)
        var input = 0
        while (true){
            print("请选择操作:")
            try{
                input = scanner.nextInt()
            }catch (e:Exception){
                print("输入不合法 ")
            }

            if (input <= 4){
                break
            }else{
                print("不能超过4 ")
            }
        }

        /*
        var type = OperationType.ADD
        when(input){
            1 -> type = OperationType.ADD
            2 -> type = OperationType.REMOVE
            3 -> type = OperationType.SHOW
        }
         */
        val type = when(input){
            1 -> OperationType.ADD
            2 -> OperationType.REMOVE
            3 -> OperationType.SHOW
            else -> OperationType.EXIT
        }

        callback(type)
    }
}